
********************************************************************************	
cd $pathdata_processed
use terminales_fin, clear

sum chance
replace chance = chance/`r(sd)'
replace expected_gpa = expected_gpa/`r(sd)'
gen expected_gpa2 = expected_gpa*expected_gpa

rename stdteachers_grades teach
rename stdteachers_grades2 teach2
********************************************************************************	    
global controls teach teach2 stdms_gpa stdms_gpa2 m_ms_gpa ///
		 female ///
		 age age2 ///
		 p_age p_age2 m_mage m_fage ///
		 p_educ p_educ2 m_mbu_kl m_fbu_kl ///
		 ln_p_inc m_mwyrkinnt_c m_fwyrkinnt_c 		
************************************************************************
global partial_gpa i.year_vg3

gen all = 1
********************************************************************************
cd $pathtable	
********************************************************************************
eststo clear			
//BC
label var chance "$\widetilde{\textrm{GPA_luck}}$"

label var expected_gpa "$\widebar{\textrm{GPA_luck}}$"
label var expected_gpa2 "$\widebar{\textrm{GPA_luck}}$, squared"
label var teach "High school course grades"
label var teach2 "High school course grades, squared"
label var stdms_gpa "Middle school GPA" 
label var stdms_gpa2 "Middle school GPA, squared" 
label var female "Female"
label var age "Age"
label var age2 "Age, squared"
label var p_age "Parents' average age"
label var p_age2 "Parents' average age, squared"
label var p_educ "Parents' average years of education"
label var p_educ2 "Parents' average years of education, squared"
label var ln_p_inc "Parents' average log earnings"
		
foreach sample in all {
			foreach var in chance {		
		
				eststo `sample'`var': areg `var' expected_gpa expected_gpa2 teach teach2 stdms_gpa stdms_gpa2 female age age2 p_age p_age2 p_educ p_educ2 ln_p_inc m_stdms_gpa m_mage m_fage m_mbu_kl m_fbu_kl m_mwyrkinnt_c m_fwyrkinnt_c $partial_gpa if `sample' == 1, cluster(group) rob absorb(skole_fo)
				
				test expected_gpa expected_gpa2 teach teach2 stdms_gpa stdms_gpa2 female age age2 p_age p_age2 p_educ p_educ2 ln_p_inc m_stdms_gpa m_mage m_fage m_mbu_kl m_fbu_kl m_mwyrkinnt_c m_fwyrkinnt_c
				estadd scalar Fstat = r(F): `sample'`var'
				estadd scalar pval = r(p): `sample'`var'
				
				su `var' if e(sample) 
				estadd r(mean): `sample'`var'
				
				}
			}
				
		esttab allchance using "BC.tex", replace booktabs legend ///
		keep(expected_gpa expected_gpa2 teach teach2 stdms_gpa stdms_gpa2 female age age2 p_age p_age2 p_educ p_educ2 ln_p_inc) cells(`"b(star fmt(4))"' `"se(fmt(4) par)"') starlevels(* 0.1 ** 0.05 *** 0.01) noobs ///
		posthead("& $\widetilde{\textrm{GPA_luck}}$ \\ \midrule") ///
		fragment stats(Fstat pval mean N, label( "F-statistic" "Joint p-value" "Mean" "N") fmt(%9.3f %9.3f %9.3f 0)) label mgroup(none) nonumbers collabels(none) eqlabels(none) mlabel(none) 
		
		eststo clear